Skip to content

[wrangler] fix: report non-zero exit code when killed by a signal (e.g. OOM)#14598

Open
matingathani wants to merge 1 commit into
cloudflare:mainfrom
matingathani:fix/wrangler-signal-exit-code
Open

[wrangler] fix: report non-zero exit code when killed by a signal (e.g. OOM)#14598
matingathani wants to merge 1 commit into
cloudflare:mainfrom
matingathani:fix/wrangler-signal-exit-code

Conversation

@matingathani

@matingathani matingathani commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #14584

bin/wrangler.js (the actual wrangler executable) spawns the real CLI (wrangler-dist/cli.js) as a child process and forwards its exit code:

.on("exit", (code) =>
	process.exit(code === undefined || code === null ? 0 : code)
)

Node's exit event fires with code = null and a populated signal when a child is killed by a signal instead of exiting normally. The handler above didn't even capture signal, and treated code === null as success — so any signal-killed wrangler process (OOM/SIGKILL as reported here, but also e.g. SIGTERM from an orchestrator timeout) silently reported exit code 0 to whatever invoked it, making CI pipelines believe the command succeeded. This applies to every wrangler command, not just pages deploy.

Root cause was found by the issue reporter (@QuentinFarizon) in the comments, including a proposed fix pattern.

Fix: capture signal, and only treat the exit as clean when a real numeric code came through. Otherwise log the signal to stderr and exit 1.

To make this testable without spawning the full built CLI or relying on cross-platform signal delivery (SIGKILL semantics differ on Windows, which this repo's CI matrix covers), the exit-code decision is extracted into a small exported resolveExitCode(code, signal) function that's unit tested directly. The file's actual CLI-spawning side effect is already guarded behind if (module === require.main), so requiring it from a test doesn't trigger a spawn.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal CLI robustness fix, no public API/behavior change for successful runs

Open in Devin Review

…g. OOM)

bin/wrangler.js's spawn().on("exit", ...) handler ignored the signal
argument entirely, treating a signal-killed child (code === null) the
same as a clean exit and calling process.exit(0). This made CI pipelines
believe wrangler succeeded when it was actually OOM-killed or otherwise
terminated by a signal. Now the signal is logged and the shim exits 1.

Fixes cloudflare#14584
Copilot AI review requested due to automatic review settings July 8, 2026 06:47
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b84853f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 8, 2026
@workers-devprod workers-devprod requested review from a team and emily-shen and removed request for a team July 8, 2026 06:48
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fix-wrangler-signal-exit-code.md: [@cloudflare/wrangler]
  • packages/wrangler/bin/wrangler.js: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/bin-wrangler-exit-code.test.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Wrangler’s wrapper executable (packages/wrangler/bin/wrangler.js) incorrectly reporting exit code 0 when the spawned CLI process is terminated by a signal (e.g. SIGKILL from OOM), which can cause CI/pipelines to treat failed runs as successful.

Changes:

  • Add resolveExitCode(code, signal) to treat signal-terminated child exits as failures and optionally log the terminating signal.
  • Update the child process "exit" handler to use resolveExitCode() instead of treating null exit codes as success.
  • Add a unit test that directly exercises resolveExitCode() without needing to spawn the full built CLI, plus a changeset entry for the patch release.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
packages/wrangler/bin/wrangler.js Adds resolveExitCode() and uses it to avoid reporting success when the child is killed by a signal.
packages/wrangler/src/tests/bin-wrangler-exit-code.test.ts Unit tests for resolveExitCode() including signal-kill scenarios.
.changeset/fix-wrangler-signal-exit-code.md Changeset documenting the behavioral fix and release impact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14598

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14598

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14598

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14598

miniflare

npm i https://pkg.pr.new/miniflare@14598

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14598

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14598

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14598

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14598

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14598

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14598

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14598

wrangler

npm i https://pkg.pr.new/wrangler@14598

commit: b84853f

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not really testing anything meaningful.

we spawn wrangler in many places including our e2e tests. could you add a test there maybe? you can add a specific windows block - we also do that in many places in our tests

@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fix-wrangler-signal-exit-code.md: [@cloudflare/wrangler]
  • packages/wrangler/bin/wrangler.js: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/bin-wrangler-exit-code.test.ts: [@cloudflare/wrangler]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

Wrangler pages deploy errors but exits without error code (status 0)

4 participants